cmake_minimum_required(VERSION 3.16)

project(ScreenShotWidget VERSION 0.1 LANGUAGES CXX)


set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core)

set(PROJECT_SOURCES
        main.cpp
)

#为main.cpp生成一个target
qt_add_executable(ScreenShotWidget
    MANUAL_FINALIZATION
    ${PROJECT_SOURCES}
)

#添加动态库并生成一个target,所以新增的头文件，cpp文件都写在这个里边
add_library(ScreenShotWidget_Lib SHARED
    ScreenShotWidget_global.h

    ScreenShotWidget.h ScreenShotWidget.cpp
    DrawLabel.h DrawLabel.cpp
    ScreenShot.h ScreenShot.cpp
    ScreenShotControlWidget.h ScreenShotControlWidget.cpp
    TextAnnotation.h TextAnnotation.cpp

)
#添加动态态库目标的头文件路径
target_include_directories(ScreenShotWidget_Lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

#动态库target的导出宏添加定义
target_compile_definitions(ScreenShotWidget_Lib PRIVATE SCREENSHOTWIDGET_LIBRARY)

#为动态库连接上Qt模块
target_link_libraries(ScreenShotWidget_Lib PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core)

#为动态库生成的target设置自动启动moc
set_target_properties(ScreenShotWidget_Lib PROPERTIES
    AUTOMOC ON
    # LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/DLL_OUTPUT/ #设置动态库输出路径

)

#主项目链接
target_link_libraries(ScreenShotWidget PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core ScreenShotWidget_Lib )

include(GNUInstallDirs)
install(TARGETS ScreenShotWidget
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)


set_target_properties(ScreenShotWidget PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)


if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(ScreenShotWidget)
endif()

#icon图标放置在res/路径下，将res文件夹拷贝到可执行文件的路径下
add_custom_command(TARGET ScreenShotWidget
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_CURRENT_SOURCE_DIR}/res/
    ${CMAKE_BINARY_DIR}/res/
)

